﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SD.Business;
using SD.DataAccess;

namespace SD.Web.Views.Contacts
{
    public partial class wucLookup : System.Web.UI.UserControl
    {
        public int ContactId
        {
            get
            {
                if (ViewState["ContactId"] == null)
                {
                    return 0;
                }
                return Convert.ToInt32(ViewState["ContactId"].ToString());
            }
            set
            {
                ViewState["ContactId"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// show popup
        /// </summary>
        public void Popup()
        {
            // author: ToanTN, version: 1.0, Date: 12 Dec 2012
            PanelContainer.CssClass = "popup";
            PanelContainer.Visible = true;
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            if (Request.Form["MyRadioButton"] != null)
            {
                // get value of radio button
                this.ContactId = Convert.ToInt32(Request.Form["MyRadioButton"].ToString());
                Contact contact = ContactBUS.GetContactById(this.ContactId);
                TextBox txtManagerName = this.Parent.FindControl("txtManagerName") as TextBox;
                if (txtManagerName != null)
                {
                    txtManagerName.Text = contact.FirstName + " " + contact.Surname;
                }
            }
            this.Visible = false;
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            if (Request.Form["MyRadioButton"] != null)
            {
                // get value of radio button
                int contactId = Convert.ToInt32(Request.Form["MyRadioButton"].ToString());
                Response.Redirect("EditContact.aspx?id=" + contactId);
            }
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

    }
}